package application;

import java.util.ArrayList;
import java.util.List;
import model.Card;
import model.Category;
import model.Client;
import model.Phone;
import model.Product;
import model.Sale;
import abstractfactory.Factory;
import dao.Card.CardDAO;
import dao.Category.CategoryDAO;
import dao.Client.ClientDAO;
import dao.Product.ProductDAO;
import dao.Sale.SaleDAO;

public class Application2 {
	public static void main(String args[]){
		long x = System.currentTimeMillis();
		
		//Relacionamento 1:1
		SaleDAO saleDao = Factory.getInstance("JPA").createSaleDAO();
		CardDAO cardDao = Factory.getInstance("JPA").createCardDAO();
		Sale sale = saleDao.list(1);
		
		Card c = new Card();
		cardDao.save(c);
		
		sale.setCard(c);
		saleDao.update(sale);
		
		//Relacionamento 1:N
		ClientDAO clientDao = Factory.getInstance("JPA").createClientDAO();
		Client client = clientDao.list(1);
		
		Phone p1 = new Phone();
		Phone p2 = new Phone();
		
		p1.setPhone("1111-1111");
		p2.setPhone("2222-2222");
		
		List<Phone> phones = new ArrayList<Phone>();
		phones.add(p1);
		phones.add(p2);
		
		client.setPhones(phones);
		
		clientDao.update(client);
		
		//Relacionamento M:N
		ProductDAO productDao = Factory.getInstance("JPA").createProductDAO();
		CategoryDAO categoryDao = Factory.getInstance("JPA").createCategoryDAO();
		
		Category c1 = categoryDao.list(50);
		Category c2 = categoryDao.list(80);
		
		List<Category> categories = new ArrayList<Category>();
		
		categories.add(c1);
		categories.add(c2);
		
		Product pr = productDao.list(1);
		pr.setCategories(categories);
		
		Product pr1 = productDao.list(2);
		pr1.setCategories(categories);
		
		productDao.update(pr);
		productDao.update(pr1);
		
		System.out.println("\n\n");
		System.out.print("Execution Time (ms): ");
		System.out.print(System.currentTimeMillis()-x);
		System.out.println("\n\n");
	}
}
